package com.cmcc.shared.adapter;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Author: jiangxin
 * Date: 2019/11/14
 * Description:
 */
public class TripOptionItemDecoration extends RecyclerView.ItemDecoration {

    private int margin;
    private int space;

    public TripOptionItemDecoration(int margin, int space) {
        this.margin = margin;
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.right = space / 2;
        outRect.left = space / 2;
        outRect.bottom = space /2;
        GridLayoutManager layoutManager = ((GridLayoutManager) parent.getLayoutManager());
        if ((parent.getChildLayoutPosition(view) % layoutManager.getSpanCount()) == layoutManager.getSpanCount() - 1) {
            outRect.right = margin;
        }
        if (parent.getChildLayoutPosition(view) == 0 || (parent.getChildLayoutPosition(view) % layoutManager.getSpanCount()) == 0) {
            outRect.left = margin;
        }
    }

}
